home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 / IRIX 6.2 CD1.iso / dist / inst.init < prev    next >
Text File  |  1996-06-11  |  11KB  |  319 lines

  1. #!/bin/sh
  2. # This script will be run by inst (or swmgr) when the distribution directory,
  3. # if placed at the top level distribution directory, with the name
  4. # "inst.init".  The user is asked if the script should be run, unless
  5. # the resource "startup_script" is set to either "ignore" or "execute",
  6. # to suppress asking the question.  Automatic installs (inst -a) fail
  7. # if this resource is not set, and this file is present.
  8. # The script has access to the normal environment variables (those that
  9. # can be used by pre-, post-, and exit-ops), such as $mr, $rbase, and
  10. # $dist.
  11. # It is invoked with 3 arguments.  The first is either "inst" or "swmgr"
  12. # for scripts that want to behave differently.  The second is the distribution
  13. # path, and the third is the file descriptor number for communicating
  14. # results/commands back to inst or swmgr.
  15. #
  16. # The script should exit with the value 0 if there are no errors
  17. # if the exit value is non-zero, a warning message is printed.
  18. #
  19. # The normal output of this script and the programs it uses are not paged
  20. # in anyway, nor is the input.  Error output (stderr, descriptor 2) is
  21. # paged.  If programs are used that use stderr, but you do not want paging
  22. # (such as rm -ri), then run them with stderr directed to normal output
  23. # (rm -ri 2>&1)
  24.  
  25. distpath="$2"
  26. if [ -z "$rbase" ]; then rbase=/; fi
  27.  
  28. case "$1" { # decided whether we need a window to run in
  29. winterm) # re-invoked from swmgr; see below
  30.     stty intr '^c' # for consistency with most usage.
  31.     endmsg='\nDistribution script completed, close this window to continue'
  32.     instfd=">$3" # for selfile creation
  33.     ;;
  34. swmgr)
  35.     # can't pass a file descriptor, so use a temporary file.
  36.     # still want to use -hold, even with the "read" confirmation
  37.     # at the end, in case there are errors.
  38.     xwsh -xrm '' -xrm 'XWsh*autoFork:false' \
  39.         -title "Software Manager - Installation Startup" -hold -e $0 winterm "$2" /tmp/$$
  40.     if [ -s /tmp/$$ ]; then cat /tmp/$$ 1>&"$3"; fi
  41.     rm -f /tmp/$$
  42.     exit 0 ;; # can not get useful exit value for this case
  43. inst|*) # if missing, or wrong, treat as inst
  44.     endmsg='\nDistribution script completed, press ENTER to continue \c'
  45.     instfd=">&$3" # for selfile creation
  46.     ;;
  47. }
  48.  
  49. # sub functions defined here; invocation at end of file {
  50.  
  51. # a *really* silly way to do paging, but with no pager in the miniroot...
  52. mypager()
  53. {
  54.       2>&1 nawk -v tl=$ttylines -F ';' \
  55.         '{ print $0; l++; \
  56.           if(!(l%tl)) { \
  57.           printf "[  Press Enter for next screen, Control-C to stop ]  "; \
  58.           getline junk < "/dev/tty" } }' $1
  59. }
  60.  
  61. docoffcheck()
  62. {
  63.     echo '\nDo you want to check your system for COFF executables now? (yes/no) [yes] \c'
  64.     read ans
  65.     case "$ans" {
  66.     y*|Y*|"") ;;
  67.     *) return ;;
  68.     }
  69.  
  70.     echo This will take a few minutes, depending on your filesystem sizes.
  71.  
  72.     if [ ! -x /coffcheck ! -x $distpath/../coffcheck ! -x /usr/sbin/coffcheck ]
  73.     then # not miniroot or local cdrom, and coffcheck not installed
  74.         rcp $distpath/../coffcheck /tmp >/dev/null 2>&1 # may be a remote install
  75.         if [ ! -x /tmp/coffcheck ]
  76.         then echo Unable to find coffcheck script, checking normal path,
  77.             echo '  this may fail.'
  78.             coffcheck # try anyway...
  79.         else /tmp/coffcheck
  80.         fi
  81.     else PATH=/:$distpath/..:/usr/sbin:$PATH coffcheck
  82.     fi
  83.  
  84.     if [ -s /var/tmp/Coff.inst_subsystems.list ] ; then 
  85.         echo The subsystems with COFF files are:\\n
  86.             mypager /usr/tmp/Coff.inst_subsystems.list
  87.     fi
  88.     if [ -s /var/tmp/Coff.files.list ] ; then 
  89.         echo 'Do you want to look at the list of COFF programs (yes/no) [yes] \c'
  90.         read ans
  91.         case "$ans" {
  92.         y*|Y*|"") mypager /usr/tmp/Coff.files.list ;;
  93.         }
  94.     fi
  95. }
  96.  
  97. rminteractive()
  98. {
  99.     echo '\nThe list of files will be shown one screen at a time, oldest first,'
  100.     echo 'in the format "owner   size   date  filename".'
  101.     echo 'For each screen, you will be prompted for each file in that screen.'
  102.     echo 'Preparing list ... \c'
  103.  
  104.     # the check for "uid # modify" is in case the login name can't be matched
  105.     # which is fairly likely for miniroot; in that case the name field will
  106.     # be printed as "uid=#".
  107.     (xargs stat -ums 2>/dev/null) < $1 | sort -t'<' +1n \
  108.         | sed -e 's/ <[0-9>]*$//' -e 's,//,/,g' \
  109.           -e 's/uid \([0-9][0-9]*\)[     ]*modify/uid \1 (uid=\1) modify/' \
  110.           -e 's/modify time - ... //' \
  111.           -e 's/ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] \(....\)$/ \1/' \
  112.           -e 's/^\([^:]*\):.*; size \([0-9][0-9]*\)[^(]*(\([^)]*\)[)     ]*\(.*\)/\3;\2;\4;\1/'\
  113.         > /tmp/rmi$$;
  114.  
  115.     if [ -s /tmp/rmi$$ ]
  116.     then # 2>&1 because the rm command prompts to stderr, we want to avoid
  117.       # the inst paging of stderr
  118.       echo ''
  119.       2>&1 nawk -v tl=$rmlines -F ';' \
  120.         '{ printf "%9s %9d %s  %s\n", $1, $2, $3, $4; f=f" "$4; l++; \
  121.           if(!(l%tl)) { printf "Use Control-C to end cleanup\n"; \
  122.           system("rm -ri" f ); f="" } } \
  123.           END { if(length(f)) { printf "Use Control-C to end cleanup\n"; \
  124.           system("rm -ri" f ) } }' /tmp/rmi$$
  125.     else echo No files found to remove # should not happen
  126.     fi
  127.     rm -f /tmp/rmi$$
  128. }
  129.  
  130. diskspace()
  131. {
  132.     echo '\nDo you want to check for kernel crash files, program core files, '
  133.     echo 'dumpster directories, temporary and lost+found files that might'
  134.     echo 'prevent a successful installation? (yes/no) [yes] \c'
  135.     read ans
  136.     case "$ans" {
  137.     y*|Y*|"") ;;
  138.     *) return ;;
  139.     }
  140.  
  141.     # figure out if we need to check /usr seperately from /
  142.     rootdev="`stat -qd /$rbase`"
  143.     usrdev="`stat -qd /$rbase/usr`"
  144.     if [ "$rootdev" != "$usrdev" ]
  145.     then dirs="$rbase $rbase/usr"
  146.     else dirs="$rbase"
  147.     fi
  148.     if [ -d $rbase/lost+found ]; then lostdirs="$lostdirs $rbase/lost+found"; fi
  149.     if [ -d $rbase/usr/lost+found ]; then lostdirs="$lostdirs $rbase/usr/lost+found"; fi
  150.     if [ -d $rbase/tmp ]; then lostdirs="$lostdirs $rbase/tmp"; fi
  151.     if [ -d $rbase/usr/tmp ]; then lostdirs="$lostdirs $rbase/usr/tmp"; fi
  152.     if [ -d $rbase/var/tmp ]; then lostdirs="$lostdirs $rbase/var/tmp"; fi
  153.  
  154.     echo Searching for large files that might need to be removed.
  155.     echo This make take a few minutes... \\c
  156.  
  157.     find $dirs -mount \( -name dumpster -type d -print \)  -o \( -name core -type f -print \) >/tmp/rm$$ 2>/dev/null
  158.     find $rbase/usr/adm/crash -mount \( -name 'unix*' -o -name 'vmcore*' \) -type f -print >>/tmp/rm$$ 2>/dev/null
  159.     # 2K and larger only, to eliminate long nuisance list...
  160.     find $lostdirs -type f -size +4 -print >> /tmp/rm$$ 2>/dev/null
  161.     echo '' # end the "Searching" line above
  162.     if [ -s /tmp/rm$$ ]
  163.       then rminteractive /tmp/rm$$
  164.       else echo \\nNo files found that might need to be removed to make space
  165.     fi
  166.     rm -f /tmp/rm$$ /tmp/rm2.$$
  167. }
  168.  
  169. oldkernel()
  170. {
  171.     if [ ! -d $rbase/var/sysgen ! -d $rbase/usr/cpu/sysgen ]
  172.     then    echo '\nNo old kernel files (used to build /unix) found.'
  173.         return
  174.     fi
  175.  
  176.     echo '\nYou may want to remove your old installed kernel (unix) object and'
  177.     echo 'configuration files that have not been modified since installation'
  178.     echo '(modified files will be saved), because their presence may prevent'
  179.     echo 'successful installation or configuration of a new kernel.\n'
  180.     echo 'You should only do this if you are planning a full IRIX installation.\n'
  181.     echo 'Do you want to remove the unmodified kernel files? (yes/no) [no] \c'
  182.     read ans
  183.     case "$ans" {
  184.     y*|Y*)
  185.         echo '\nChecking for modified files; may take a few minutes. \c'
  186.         showfiles -smr $rbase -- /var/sysgen 2>/dev/null |\
  187.             sed s,var/sysgen/,, > /tmp/modvar$$
  188.         showfiles -smr $rbase -- /usr/cpu/sysgen 2>/dev/null |\
  189.             sed s,usr/cpu/sysgen/,, > /tmp/modusr$$
  190.         if [ -s /tmp/modvar$$ -o -s /tmp/modusr$$ ]; then
  191.         if [ -s /tmp/modvar$$ ]; then
  192.             echo \\nModified installed kernel files saved in /var/sysgen.O:
  193.             mkdir -p $rbase/var/sysgen.O
  194.             # errs will be on files "modified" because they are missing.
  195.             (cd $rbase/var/sysgen && cpio -dmp $rbase/var/sysgen.O \
  196.                 </tmp/modvar$$) >/dev/null 2>&1
  197.             (cd $rbase/var/sysgen.O && (l="`echo *`"; if [ "$l" != '*' ];
  198.                 then find * -type f -print; fi))
  199.  
  200.         fi
  201.         if [ -s /tmp/modusr$$ ]; then
  202.             echo \\nModified installed kernel files saved in /usr/cpu/sysgen.O:
  203.             mkdir -p $rbase/usr/cpu/sysgen.O
  204.             # errs will be on files "modified" because they are missing.
  205.             (cd $rbase/usr/cpu/sysgen && cpio -dmp $rbase/usr/cpu/sysgen.O \
  206.                 </tmp/modusr$$) >/dev/null 2>&1
  207.             (cd $rbase/usr/cpu/sysgen.O && (l="`echo *`"; if [ "$l" != '*' ];
  208.                 then find * -type f -print; fi))
  209.         fi
  210.         else echo . Note: no modified kernel files exist.
  211.         fi
  212.         rm -f /tmp/mod*$$
  213.         echo '\nRemoving kernel directories var/sysgen and usr/cpu/sysgen'
  214.         rm -rf $rbase/var/sysgen $rbase/usr/cpu/sysgen
  215.         ;;
  216.     }
  217. }
  218.  
  219.  
  220. oldunix()
  221. {
  222.     # this is mainly so we don't run out of space on the miniroot when we
  223.     # try to save the old kernel there, but it can help a lot with the install
  224.     # itself also.
  225.     rootfree=7168 # 7MB; more than enough for the largest kernel we know of
  226.  
  227.     set `df -k $rbase | sed -n '$p'`
  228.     if [ "$5" -lt $rootfree -s $rbase/unix ]
  229.     then
  230.         echo "\nYou have limited free space on your root filesystem ($5 KB)."
  231.         echo 'This may cause some problems in completing your installation.'
  232.         echo 'If you are installing kernel drivers, or the full OS, you'
  233.         echo 'may wish to remove your current /unix to create more space.'
  234.         echo '(This should not be done if you are installing new drivers or'
  235.         echo 'the full IRIX release.)  Do you wish to remove /unix? (yes/no) [no] \c'
  236.         read ans
  237.         case "$ans" {
  238.         y*|Y*) rm $rbase/unix && echo Removed old /unix ;;
  239.         }
  240.     fi
  241. }
  242.  
  243. # see if we should tell inst to default xfs, lv, xlv install or not
  244. selectfsmodules()
  245. {
  246.     if [ -s $rbase/etc/lvtab ]
  247.     then echo install eoe.sw.lv >> /tmp/selfile$$
  248.     fi
  249.     if [ -d $rbase/dev/dsk/xlv ]
  250.     then echo install eoe.sw.xlv >> /tmp/selfile$$
  251.     fi
  252.     if [ "$rbase" = /root ]
  253.     then df | egrep -v '/$' > /tmp/fs$$
  254.     else df > /tmp/fs$$
  255.     fi
  256.     if grep ' xfs ' /tmp/fs$$ >/dev/null
  257.     then echo install eoe.sw.xfs >> /tmp/selfile$$
  258.     fi
  259.     if grep ' efs ' /tmp/fs$$ >/dev/null
  260.     then echo install eoe.sw.efs >> /tmp/selfile$$
  261.     fi
  262.     if [ -s /tmp/selfile$$ ]
  263.     then eval cat /tmp/selfile$$ $instfd
  264.     fi
  265.     rm -f /tmp/fs$$ /tmp/selfile$$
  266. }
  267.  
  268. # a function so the 'return' in the trap handler works right.
  269. endit()
  270. {
  271.     rm -f /tmp/*$$*; echo "$endmsg"; read answer
  272. }
  273.  
  274. # }
  275.  
  276. # main sequence starts here, using the functions above
  277.  
  278.  
  279. # Check done after xwsh opened if swmgr used, so it's visible.
  280. if [ "$instmode" = "client" -o "$instmode" = "prototype" ]
  281. then echo This script should only be run if you are not installing software
  282.     echo into an alternate location.  Nothing to do, since -r used.
  283.     endit
  284.     exit 0
  285. fi
  286.  
  287. # for paging, and interactive file removal list.  Does not deal with linewrap
  288. ttylines=`stty -a 2>/dev/null|grep rows|sed 's/.*\( [0-9][0-9]*\) rows.*/\1/'`
  289. if [ "$ttylines" -le 0 ]
  290.     then ttylines=24  # assume serial console
  291. elif [ "$ttylines" -le 10 ]
  292.     then ttylines=10 # need a reasonable amount of space...
  293. fi
  294. ttylines=`expr $ttylines - 1` # leave room for prompt at bottom
  295. rmlines=`expr $ttylines - 4` # context, and some linewrap
  296.  
  297.  
  298. # abort the current function, and continue with the next one,
  299. # if we get an interrupt
  300. trap 'echo \\n\\nInterrupted\\n; return' 2 3 15
  301.  
  302. echo '\nTo stop the current cleanup activity, press Control-C at any time\n'
  303.  
  304. docoffcheck
  305.  
  306. diskspace
  307.  
  308. oldkernel
  309.  
  310. oldunix
  311.  
  312. selectfsmodules
  313.  
  314. endit
  315.  
  316. exit 0
  317.